package com.zhuozhengsoft.pageoffice6springboot2back.controller.insertSeal;

import com.zhuozhengsoft.pageoffice.*;
import com.zhuozhengsoft.pageoffice6springboot2back.util.GetDirPathUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = "/InsertSeal/Word")
public class WordInsertSealController {
    //获取doc目录的磁盘路径
    private String dir = GetDirPathUtil.getDirPath() + "static/doc/";

    @RequestMapping(value = "/AddSeal/Word1")
    public String showWord(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        //设置保存页面
        poCtrl.setSaveFilePage("/InsertSeal/Word/AddSeal/save");

        //打开Word文档
        poCtrl.webOpen("/doc/InsertSeal/Word/AddSeal/test1.docx", OpenModeType.docNormalEdit, "张三");
        return poCtrl.getHtmlCode();
    }


    @RequestMapping(value = "/AddSeal/Word2")
    public String showWord2(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        //设置保存页面
        poCtrl.setSaveFilePage("/InsertSeal/Word/AddSeal/save");

        //打开Word文档
        poCtrl.webOpen("/doc/InsertSeal/Word/AddSeal/test2.docx", OpenModeType.docNormalEdit, "张三");
        return poCtrl.getHtmlCode();
    }

    @RequestMapping(value = "/AddSeal/Word8")
    public String showWord8(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        //设置保存页面
        poCtrl.setSaveFilePage("/InsertSeal/Word/AddSeal/save");
        //打开Word文档
        poCtrl.webOpen("/doc/InsertSeal/Word/AddSeal/test8.docx", OpenModeType.docNormalEdit, "张三");
        return poCtrl.getHtmlCode();
    }



    @RequestMapping(value = "/AddSign/Word1")
    public String showWord11(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);

        //设置保存页面
        poCtrl.setSaveFilePage("/InsertSeal/Word/AddSign/save");//设置处理文件保存的请求方法

        //打开Word文档
        poCtrl.webOpen("/doc/InsertSeal/Word/AddSign/test1.docx", OpenModeType.docNormalEdit, "张三");
        return poCtrl.getHtmlCode();
    }


    @RequestMapping(value = "/AddSign/Word2")
    public String showWord12(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);

        //设置保存页面
        poCtrl.setSaveFilePage("/InsertSeal/Word/AddSign/save");//设置处理文件保存的请求方法

        //打开Word文档
        poCtrl.webOpen("/doc/InsertSeal/Word/AddSign/test2.docx", OpenModeType.docNormalEdit, "张三");
        return poCtrl.getHtmlCode();
    }

    @RequestMapping(value = "/AddSign/Word5")
    public String showWord15(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        //设置保存页面
        poCtrl.setSaveFilePage("/InsertSeal/Word/AddSign/save");//设置处理文件保存的请求方法
        //打开Word文档
        poCtrl.webOpen("/doc/InsertSeal/Word/AddSign/test5.docx", OpenModeType.docNormalEdit, "张三");
        return poCtrl.getHtmlCode();
    }


    @RequestMapping("/AddSeal/save")
    public void save(HttpServletRequest request, HttpServletResponse response) {
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(dir + "InsertSeal/Word/AddSeal/" + fs.getFileName());
        fs.close();
    }

    @RequestMapping("/AddSign/save")
    public void save2(HttpServletRequest request, HttpServletResponse response) {
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(dir + "InsertSeal/Word/AddSign/" + fs.getFileName());
        fs.close();
    }

}
